package  
{
	import org.flixel.*;
	import org.flixel.FlxState;
	
	/**
	 * ...
	 * @author Enric Llagostera
	 */
	public class TestBed extends FlxState 
	{
		[Embed(source = "../assets/TestLevel.png")] private var imgTestLevel:Class;
		
		public var topMessage:FlxText;
		
		public var map:FlxTilemap;
		
		public var p1:BlockyPlayer;
		public var p2:SplashPlayer;
		public var p3:SplashPlayer;
		
		override public function create():void {
			super.create();
			
			FlxG.bgColor = 0xffff00ff;
			
			topMessage = new FlxText(FlxG.width/2-50, 100, 150, "WET PLOOSHY PLOOSHY");
			add(topMessage);
			
			map = new FlxTilemap();
			
			map.loadMap(FlxTilemap.imageToCSV(imgTestLevel, false, 1), FlxTilemap.ImgAuto, 8, 8, FlxTilemap.AUTO,0,1,1);
			
			add(map);
			
			Registry.groupTemp = new FlxGroup();
			
			Registry.groupSplash = new FlxGroup();
			
			
			Registry.groupBlocks = new FlxGroup();
			add(Registry.groupBlocks);
			
			p1 = new BlockyPlayer(120, 120, 1, "W", "S", "A", "D", "T", "Y", "R");
			add(p1);
			
			p2 = new SplashPlayer(200, 200, "W", "S", "A", "D", "SPACE");
			add(p2);
			
			p3 = new SplashPlayer(200, 200, "I", "K", "J", "L", "O");
			add(p3);
			
			//p2.drag = new FlxPoint(10000, 10000);
			
			add(Registry.groupTemp);
			
			add(Registry.groupSplash);
			
		}
		
		public function particleOverlap(pushed:FlxSprite, particle:SplashParticle):void {
			
			if (pushed != particle.owner) {
				pushed.velocity.x += particle.velocity.x / 10;
				pushed.velocity.y += particle.velocity.y/ 10;
			}
			
			
			
		}
		
		override public function update():void {
			super.update();
			
			FlxG.collide(p1, map);
			FlxG.collide(p2, map);
			FlxG.collide(p3, map);
			FlxG.collide(Registry.groupBlocks, map);
			FlxG.collide(Registry.groupSplash, map);
			FlxG.collide(p1, Registry.groupBlocks);
			FlxG.collide(p2, Registry.groupBlocks);
			FlxG.collide(p3, Registry.groupBlocks);
			
			FlxG.collide(p1, p2);
			
			FlxG.collide(Registry.groupSplash);
			
			
			FlxG.overlap(p1, Registry.groupSplash, particleOverlap);
			FlxG.overlap(p2, Registry.groupSplash, particleOverlap);
			FlxG.overlap(p3, Registry.groupSplash, particleOverlap);
			
			FlxG.overlap(Registry.groupBlocks, Registry.groupSplash, particleOverlap);
		}
		
		
		
	}

}